package cn.huanba.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 全局过滤器无需注册（@Configuration）
 */
@Component
public class CustomGlobalFilter implements GlobalFilter, Ordered {
    /**
     * 业务过滤器
     * @param exchange
     * @param chain
     * @return
     */
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println("自定义全局过滤器");
        return chain.filter(exchange);
    }

    /**
     * 执行优先级
     * @return
     */
    @Override
    public int getOrder() {
        return 0;
    }
}
